package com.wanpinghui.supplier.object.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wanpinghui.supplier.R;
import com.wanpinghui.wphlibrary.model.object.bean.FollowRecordBean;
import com.yunshl.yunshllibrary.recyclerview.BaseRecyclerViewAdapter;
import com.yunshl.yunshllibrary.utils.TextUtil;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/12/5
 ***/

public class FollowRecordAdapter extends BaseRecyclerViewAdapter<FollowRecordBean, FollowRecordAdapter.FollowHolder> {

    public FollowRecordAdapter(Context context) {
        super(context);
    }

    @Override
    public FollowHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_recv_follow, null);
        return new FollowHolder(view);
    }

    @Override
    public void onBindViewHolder(FollowHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        if (datas.get(position).getFollow_type() == 1) {
            holder.textViewStatus.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryBlue));
            holder.textViewStatus.setText("独家锁定");
            holder.textViewName.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryTwo));
            holder.textViewMobile.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryTwo));
            holder.textViewMsg.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryTwo));
            holder.textViewName.setText(datas.get(position).getNickname());
            if (TextUtil.isNotEmpty(datas.get(position).getFollow_msg())){
//                holder.textViewMsg.setVisibility(View.VISIBLE);
//                holder.textViewMsg.setText("理由: " + datas.get(position).getFollow_msg());
            }else {
//                holder.textViewMsg.setVisibility(View.INVISIBLE);
            }

            holder.textViewMobile.setText(datas.get(position).getMobile());
        } else if (datas.get(position).getFollow_type() == 2) {
            holder.textViewStatus.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryBlue));
            holder.textViewStatus.setText("继续跟进");
            holder.textViewName.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryTwo));
            holder.textViewMobile.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryTwo));
            holder.textViewMsg.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryTwo));
            holder.textViewName.setText(datas.get(position).getNickname());
            if (TextUtil.isNotEmpty(datas.get(position).getFollow_msg())){
//                holder.textViewMsg.setVisibility(View.VISIBLE);
//                holder.textViewMsg.setText("理由: " + datas.get(position).getFollow_msg());
            }else {
//                holder.textViewMsg.setVisibility(View.INVISIBLE);
            }

            holder.textViewMobile.setText(datas.get(position).getMobile());
        } else {
            holder.textViewStatus.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryHint));
            holder.textViewName.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryHint));
            holder.textViewMobile.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryHint));
            holder.textViewMsg.setTextColor(ContextCompat.getColor(context, R.color.colorTextPrimaryHint));
            holder.textViewStatus.setText("取消跟进");
            holder.textViewName.setText(datas.get(position).getNickname());
            if (TextUtil.isNotEmpty(datas.get(position).getFollow_msg())){
//                holder.textViewMsg.setVisibility(View.VISIBLE);
//                holder.textViewMsg.setText("理由: " + datas.get(position).getFollow_msg());
            }else {
//                holder.textViewMsg.setVisibility(View.INVISIBLE);
            }

            holder.textViewMobile.setText(datas.get(position).getMobile());
        }
        if (position == getItemCount() - 1) {
            holder.viewLine.setVisibility(View.GONE);
        } else {
            holder.viewLine.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public boolean isAllCancle(){
        boolean isAllCancle=true;
      if(datas!=null && datas.size()>0){
            for(FollowRecordBean frb:datas){
                if(frb.getFollow_type()!=3){
                    isAllCancle=false;
                    break;
                }
            }
       }
       return isAllCancle;
    }

    class FollowHolder extends RecyclerView.ViewHolder {
        TextView textViewName;
        TextView textViewMobile;
        TextView textViewMsg;
        TextView textViewStatus;
        View viewLine;

        public FollowHolder(View itemView) {
            super(itemView);
            textViewName = (TextView) itemView.findViewById(R.id.tv_user_name);
            textViewMobile = (TextView) itemView.findViewById(R.id.tv_phone);
            textViewMsg = (TextView) itemView.findViewById(R.id.tv_message);
            textViewStatus = (TextView) itemView.findViewById(R.id.tv_status);
            viewLine = itemView.findViewById(R.id.view_line);
            itemView.setLayoutParams(new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
    }
}
